// 输入一串数字, 假象它为二叉搜索树, 构造二叉树, 最后前序遍历, 看和输入是否一致
// 如果是二叉搜索树, 求伞缀
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

class TreeNode {
    constructor(value, left = null, right = null) {
        this.value = value
        this.left = left
        this.right = right
    }
}


let initArr = [];
rl.on("line", (line)=>{
    if(initArr.length === 0) {
        initArr = line.trim().split(/\s+/).map(Number)
        console.log(getResult(initArr))
        // clear
        initArr.length = 0

    }

})

function  getResult(initArr) {
    // 构造二叉树
    let root = constructTree(JSON.parse(JSON.stringify(initArr)))

    // 二叉树前序遍历
    let ans = []
    preTraversal(root, ans)
    if(ans.join("") !== initArr.join("")) {
        return "0 0 0"
    }
    if(ans.length === 1) {
        return "1 0 0"
    }

    //有什么特殊的技巧吗? 先按常规的来:左侧重点取左, 右侧重点取右
    let left = getLeft(root.left)
    let right = getLeft(root.right)
    return `1 ${left} ${right}`
}

function constructTree(initArr) {
    if(initArr.length === 0) return
    let num = initArr.shift()
    let root = new TreeNode(num)
    let leftArr = []
    let rightArr = []
    for (const number of initArr) {
        if(number > num) {
            rightArr.push(number)
        } else {
            leftArr.push(number)
        }
    }
    root.left = constructTree(leftArr)
    root.right = constructTree(rightArr)
    return root
}

function preTraversal(tree, ans) {
    ans.push(tree.value)
    let left = tree.left
    let right = tree.right
    if(left) {
        preTraversal(left, ans)
    }
    if(right) {
        preTraversal(right, ans)
    }
}

function getLeft(root){
    if(root === null) return 0
    let left = root.left
    let right = root.right
    // 取值
    if(!left && !right) {
        return  root.value
    }
    if(left) {
        return  getLeft(left)
    }
    if(!left && right) {
        return  getLeft(right)
    }
}
function getRight(root){
    if(root === null) return 0
    let left = root.left
    let right = root.right
    // 取值
    if(!left && !right) {
        return  root.value
    }
    if(right) {
        return  getLeft(right)
    }
    if(left && !right) {
        return  getLeft(left)
    }
}